package org.streets.wicket;

import org.apache.wicket.Page;
import org.apache.wicket.Response;
import org.apache.wicket.protocol.http.WebRequest;
import org.apache.wicket.protocol.http.WebRequestCycle;

import org.streets.context.HiveRegistry;

public class HiveRequestCycle extends WebRequestCycle {

	protected final HiveRegistry registry;
	
	public HiveRequestCycle(HiveWebApplication application, WebRequest request,
			Response response) {
		super(application, request, response);		
		registry = application.getRegistry();		
	}

	@Override
	protected void onBeginRequest() {
		super.onBeginRequest();
		registry.setupThread();
	}
	
	@Override
	protected void onEndRequest() {
		registry.cleanupThread();
		super.onEndRequest();		
	}
	
    @Override         
    public Page onRuntimeException(Page page, RuntimeException e) {
    	registry.cleanupThread();    	
    	return super.onRuntimeException(page, e);         
    }
}
